﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Bamboo.Helpers
{
    public static class StringExtensions
    {
        public static string Titlize(this string text)
        {
            return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);            
        }
        public static string TruncateFullWord(this string value, int length)
        {
            //if (length <= 0) return string.Empty;
            //if (value == null || value.Length < length || value.LastIndexOf(" ", length) == -1)
            //    return value;

            //value = value.Substring(0, value.LastIndexOf(" ", length));

            //if (value.Length > length && value.LastIndexOf(" ") == -1) return value;

            //return string.Format("{0} ...", value.Substring(0, value.LastIndexOf(" ")));

            if (value == null || value.Length < length)
                return value;
            int iNextSpace = value.LastIndexOf(" ", length);
            return string.Format("{0} ...", value.Substring(0, (iNextSpace > 0) ? iNextSpace : length).Trim());


        }

    }
}
